<template>
  <div class="list">
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索区域 -->
    <div style="margin-top: 15px;">
      <el-input
        v-model="params.query"
        style="width:300px;margin-right:15px"
        placeholder="请输入内容"
        class="input-with-select"
      >
        <el-button slot="append" icon="el-icon-search" @click='init'></el-button>
      </el-input>
      <el-button type="primary" @click="addshow">添加商品</el-button>
    </div>
    <el-table :data="allGoodsList" border style="width: 100%">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="goods_name" label="商品名称" width="500"></el-table-column>
      <el-table-column prop="goods_price" label="商品价格" width="180"></el-table-column>
      <el-table-column prop="goods_state" label="商品状态"></el-table-column>
      <el-table-column prop="goods_weight" label="商品重量"></el-table-column>
      <el-table-column prop="upd_time" label="创建时间"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" >编辑</el-button>
          <el-button size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
          @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="params.pagenum"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="params.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total-0">
    </el-pagination>
  </div>
</template>
<script>
import { GoodsList } from '@/api/goods.js'
export default {
  data () {
    return {
      total: '',
      params: {
        query: '',
        pagenum: 2,
        pagesize: 10
      },
      allGoodsList: []
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    addshow () {
      this.$router.push({ name: 'add' })
    },
    // 渲染页面数据
    init () {
      GoodsList(this.params)
        .then(res => {
          // console.log(res)
          if (res.data.meta.status === 200) {
            this.allGoodsList = res.data.data.goods
            this.total = res.data.data.total
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    handleSizeChange (val) {
      this.params.pagesize = val
      this.init()
      console.log(val)
    },
    handleCurrentChange (val) {
      this.params.pagenum = val
      this.init()
      console.log(val)
    }
  }
}
</script>
<style lang="less" scoped>
</style>
